//
//  HZRootViewController.m
//  DarenForum
//
//  Created by 刘华舟 on 15/4/2.
//  Copyright (c) 2015年 刘华舟 khzliu@163.com. All rights reserved.
//

#import "HZRootViewController.h"
#import "HZColorConstant.h"


@interface HZRootViewController ()<HZForumLeftBarItemsDelegate,UIGestureRecognizerDelegate>

@property (strong, nonatomic) HZForumLeftBarItems *forumLeftBarItems;
@property (strong, nonatomic) UIBarButtonItem *leftBarItems;

@property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipeGestureRecognizer;
@property (nonatomic, strong) UISwipeGestureRecognizer *rightSwipeGestureRecognizer;


@end

@implementation HZRootViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.barTintColor = nil;
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    self.navigationController.navigationBar.backgroundColor = HZ_CLEAR_COLOR;
    
//    self.navigationController.fd_interactivePopDisabled = YES;
//    self.fd_interactivePopDisabled = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = HZ_WHITE_COLOR;
    
    self.forumLeftBarItems = [[HZForumLeftBarItems alloc] initWithFrame:CGRectOf([self.view.ufo ux:0 uy:0],
                                                                                 [self.view.ubo uw:120 uh:80])];
    self.forumLeftBarItems.delegate = self;
    self.leftBarItems = [[UIBarButtonItem alloc] initWithCustomView:self.forumLeftBarItems];
    
    self.navigationItem.backBarButtonItem = self.leftBarItems;
//    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
//    self.navigationController.interactivePopGestureRecognizer.delegate = self;
//    self.view.translatesAutoresizingMaskIntoConstraints = YES;
//    self.automaticallyAdjustsScrollViewInsets = YES;
    
    
    self.leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
    self.rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];
    
    self.leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
    self.rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
    
    [self.view addGestureRecognizer:self.leftSwipeGestureRecognizer];
    [self.view addGestureRecognizer:self.rightSwipeGestureRecognizer];
    
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.barTintColor = nil;
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBar.backgroundColor = HZ_CLEAR_COLOR;
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    
}


#pragma mark - 返回
- (void)backForumWith:(HZForumLeftBarItems *)forumLeftBarItems{
    
    NSLog(@"点击返回");

    [self.navigationController popViewControllerAnimated:YES];
    
    
}


- (void)handleSwipes:(UISwipeGestureRecognizer *)sender
{
    if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
        if (self.targetCallerSwipeLeft) {
            [self.targetCallerSwipeLeft call];
        }
    }
    
    if (sender.direction == UISwipeGestureRecognizerDirectionRight) {
        if (self.targetCallerSwipeRight) {
            [self.targetCallerSwipeRight call];
        }
    }
}

- (void)fillLeftBackTitle:(NSString *)title{
    //[self.forumLeftBarItems.titleNameLabel setText:title];
    self.title = title;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    if (self.navigationController.viewControllers.count <= 1)//关闭主界面的右滑返回
    {
        return NO;
    }else{
        return YES;
    }
}

@end
